<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>
        REST call from Ruby
    </title>
    <script src="../../js/jquery.js" type="text/javascript"></script>
    <script src="../../js/gestalt.js" type="text/javascript"></script>
</head>
<body>
<h1>Hi there, world. </h1>
<xml id="world" class="xaml" Width="800" Height="600" style="display:none;">
    <StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Name="palate" Width="800" Height="600">
	    <StackPanel Orientation="Horizontal">
	        <Button x:Name="add_time" Content="What time is it, client?"></Button>
	        <Button x:Name="add_remote_time" Content="What time is it, server?"></Button>
	    </StackPanel>
    </StackPanel>
</xml>
<div id="msg"> </div>
<script class="*" language="ruby">
include System
include System::Net
def adding_time_from_client(s,e)
	add_time DateTime.now.to_s
end

def adding_time_from_server(s,e)
	client = WebClient.new
	client.DownloadStringCompleted{|s,e| add_time(e.Result)}
	uri = Uri.new document.DocumentUri, "server_time.ashx"
	client.DownloadStringAsync uri
end

def add_time(t)
	clock = TextBlock.new
	clock.Text = t
	me.palate.children.add clock
end
me.add_time.Click{|s,e| adding_time_from_client(s,e)}
me.add_remote_time.Click{|s,e| adding_time_from_server(s,e)}
add_time(DateTime.now.to_s)
</script>
</body>
</html>